package com.jbm.enterapplication.utlisclass

import android.content.Context
import com.jbm.onehome.iface.IEGuardKey
import java.io.*
import java.util.*

/**
 * Created by 家帮忙 on 2017/1/23.
 */

class SaveOpenKeyManage(internal var context: Context) {

    /**
     * 保存用户的开门key
     */
    private var opfile: FileOutputStream? = null
    private var obfile: ObjectOutputStream? = null
    fun setsaveOpenkey(ArrayListIEKey: ArrayList<IEGuardKey>) {
        try {
            opfile = context.openFileOutput("openkey.txt", 0)
            obfile = ObjectOutputStream(opfile)
            obfile!!.writeObject(ArrayListIEKey)
            obfile!!.flush()
        } catch (e: Exception) {
            e.printStackTrace()
        } finally {
            if (obfile != null) {
                try {
                    obfile!!.close()
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }

        }

    }

    /**
     * 获取用户的key
     */
    private var infile: FileInputStream? = null
    private var obinfile: ObjectInputStream? = null
    private var arrIEguar: ArrayList<IEGuardKey>? = null
    fun setgainOpenKey(): ArrayList<IEGuardKey> {
        try {
            infile = context.openFileInput("openkey.txt")
            obinfile = ObjectInputStream(infile)
            if (obinfile != null)
                arrIEguar = obinfile!!.readObject() as ArrayList<IEGuardKey>
        } catch (e: Exception) {
            e.printStackTrace()
        } finally {
            try {
                if (obinfile != null)
                    obinfile!!.close()

            } catch (e: IOException) {
                e.printStackTrace()
            }

        }
        return arrIEguar!!

    }

}
